package cn.zhj.service.impl;

import cn.zhj.domain.Student;
import cn.zhj.mapper.StudentMapper;
import cn.zhj.query.StudentQuery;
import cn.zhj.service.IStudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
@Slf4j
public class StudentServiceImpl implements IStudentService {
    @Autowired
    private StudentMapper studentMapper;// idea没识别，不影响
    @Override
    public Student findOne(int id) {
//        employeeMapper.findOne(id);
        return studentMapper.findOne(id);
    }

    @Override
    public List<Student> findAll() {
        return studentMapper.findAll();
    }

    @Transactional
    @Override
    public void insert(Student student) {
        studentMapper.insert(student);
    }

    @Transactional
    @Override
    public void delete(int id) {
        studentMapper.delete(id);
    }

    @Transactional
    @Override
    public void update(Student student) {
        studentMapper.update(student);
    }

    @Override
    public Map<String, Object> queryPage(StudentQuery studentQuery) {
        Map<String, Object> map = new HashMap<>();
        Integer totals = studentMapper.getCount(studentQuery);
        List<Student> data = studentMapper.getData(studentQuery);
        map.put("totals",totals);
        map.put("data",data);
        return map;
    }

    @Transactional
    @Override
    public void patchDeL(Integer[] ids) {
        studentMapper.patchDeL(ids);
    }
}
